<?php
/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2018/9/30
 * Time: 11:24
 */
namespace app\admin\model;
use think\Db;
use think\Model;

class SzxinxiangModel extends Model
{
    /**
     * 获取器
     */
    public function getIsgongkaiAttr($value)
    {
        $iggongkai = [1=>'是',2=>'否'];
        return $iggongkai[$value];
    }

    //获取列表,其中dealunit,应该绑定的是用户的id；
    public function getMsgList($where){
        return $this->where($where)->field('id,type,findcode,title,isgongkai,create_time,zhuantime,overtime,dealunit')->paginate(15);

    }
    //获取列表数量，
    public function getCount($where){
        return $this->where($where)->count();
    }
    //获取单位名称
    public function getUnitname($where){
        $res =  Db::table('qy_user')->where($where)->value('user_nickname');
        return $res;
    }
    public function getMsgList1($where){
        return   Db::table('qy_szxinxiang')
            ->alias('s')
            ->where($where)
            ->join('qy_user u' ,'s.dealunit = u.id','left')
            ->field('s.deal,s.id,s.type,s.findcode,s.title,s.isgongkai,s.create_time,s.zhuantime,s.overtime,u.user_nickname as unitname ,s.dealunit')
            ->paginate(15);

    }



    //查询内容
    public function getMsgdet($where){
        return $this->where($where)->find();
    }
    //更改内容,$where 需包含主键
    public function upDeal($where){
        return $this->update($where);
    }


    //删除
    public function del($id)
    {
    return  Db::table('qy_szxinxiang')
          ->where('id',$id)
          ->delete();
    }

    public function msg($where)
    {
      return   Db::table('qy_szxinxiang')
            ->alias('s')
            ->where($where)
            ->find();

    }
//更换deal 状态 到 2
    public function dealTo2($id,$dealunit)
    {
        return Db::table('qy_szxinxiang')
            ->where('id',$id)
            ->update(['deal' => 2,'dealunit' =>$dealunit]);
    }

    //更换内容
    public function changeContent($id, $content)
    {
        return Db::table('qy_szxinxiang')
            ->where('id',$id)
            ->update(['content' => $content]);
    }
    //修改受理单位dealunit
    public function dealUnit($id,$dealunit)
    {
        return Db::table('qy_szxinxiang')
            ->where('id',$id)
            ->update(['dealunit' => $dealunit]);
    }
    //跟换deal 状态
    public function deal($id,$deal)
    {
        return  Db::table('qy_szxinxiang')
            ->where('id',$id)
            ->update(['deal'=> $deal]);
    }

   // 添加结束时间
public function overTIme($id)
{$time = time();
    return Db::table('qy_szxinxiang')
        ->where('id',$id)
        ->update(['overtime' => $time]);
}
}